package com.mymvc.controller.restful;

import com.mymvc.controller.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王俊彪
 * @version 1.0
 */
@Controller("userController01")
@RequestMapping("/user")
public class UserController {

    @GetMapping("/{id}")
    public @ResponseBody User findById(@PathVariable("id") Integer uid){
        return new User(uid,"zhangsan","123456");//模拟在数据库查询到的数据
    }
    @PostMapping
    public String sadveUser(@RequestBody User user){
        System.out.println("将数据保存到数据库");
        System.out.println(user);
        return "success";
    }

    @GetMapping("/restful")
    public String restful(){
        return "restful";
    }

    @PutMapping
    public String updateUser(User user){
        System.out.println("将数据进行了修改");
        System.out.println(user);
        return "success";
    }

    @DeleteMapping("/{id}")
    public String deleteUser(@PathVariable("id") int uid){
        System.out.println("删除了元素id为:" + uid);
        return "success";
    }
}
